home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / koprosrc.lzh / tbase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-14  |  1.6 KB  |  80 lines

  1. /*    Copyright 1992 H.Ogasawara (COR.)    */
  2.  
  3. #include    <sys_doslib.h>
  4.  
  5.  
  6. /* てきとーに作った時間変換ルーチン */
  7.  
  8. #include    "tbase.h"
  9.  
  10. #define        FTIME    1970
  11.  
  12. static char    month_tbl[]= { 31,28,31,30,31,30,31,31,30,31,30,31 };
  13.  
  14. /* こんな変換ルーチンで本当にいいのだろうか ?? (2000年で誤差が出ます) */
  15. sectotime( time, tb )
  16. T_BASE    *tb;
  17. {
  18.     unsigned short    i;
  19.     int        year;
  20.     tb->sec = time % 60;
  21.     tb->min = (time/=60) % 60;
  22.     tb->hour= (time/=60) % 24;
  23.     year    = (time/=24) /365;
  24.     time    %= 365;
  25.     if( (time-= (year+1)/4) < 0 )
  26.         year--, time+= 365;
  27.     year+= FTIME;
  28.     for( i= 0 ; tb->day= time+1, (time -= month_tbl[i]) >= 0 ; i++ )
  29.         if( i == 1 && !(year & 3) && (--time < 0 ) )
  30.             break;
  31.     tb->year= year;
  32.     tb->month= i+1;
  33. }
  34.  
  35. timetosec( tb )
  36. T_BASE    *tb;
  37. {
  38.     unsigned short    i;
  39.     int        time;
  40.     time = tb->sec;
  41.     time+= tb->min*60;
  42.     time+= tb->hour*60*60;
  43.     time+= (tb->day-1)*60*60*24;
  44.     time+= (tb->year-FTIME)*365*60*60*24;
  45.     time+= ((tb->year-FTIME+2)/4)*60*60*24;
  46.  
  47.     for( i= 0 ; i < tb->month-1 ; i++ )
  48.         time+= month_tbl[i]*60*60*24;
  49.     return    time;
  50. }
  51.  
  52. /*    夏時間は見ない    */
  53. gettz()
  54. {
  55.     char    buf[256];
  56.     if( GETENV( "TZ", 0, buf ) >= 0 )
  57.         return    atoi2( buf+3 );
  58.     return    -9;
  59. }
  60.  
  61. #if 0
  62. main()
  63. {
  64.     T_BASE    t,tt;
  65.     int    a;
  66.     t.sec= 0;
  67.     t.min= 58;
  68.     t.hour= 15;
  69.     t.day= 30;
  70.     t.month= 5;
  71.     t.year= 1992;
  72.     a= timetosec( &t );
  73.     printf( "sec= %d  (%d)\n", a, time(0) );
  74.     sectotime( a, &tt );
  75.     printf("%d/%02d/%02d %02d:%02d:%02d\n",tt.year,tt.month,tt.day,tt.hour,tt.min,tt.sec );
  76.     sectotime( time(0)+9*60*60, &tt );
  77.     printf("%d/%02d/%02d %02d:%02d:%02d\n",tt.year,tt.month,tt.day,tt.hour,tt.min,tt.sec );
  78. }
  79. #endif
  80.